package com.atguigu.upp.service;

import com.atguigu.upp.mapper.ClickHouseMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import javax.swing.text.html.HTML;

/**
 * Created by Smexy on 2023/1/4
 */
public class ClickhouseService
{
    private ClickHouseMapper clickHouseMapper;

    public ClickhouseService(SqlSession sqlSession){
        this.clickHouseMapper = sqlSession.getMapper(ClickHouseMapper.class);
    }

    public void createWideTable(String table,String tag){
        validArgs(table,tag);
        clickHouseMapper.createWideTable(table,tag);
    }
    public void dropWideTable(String table){
        validArgs(table);
        clickHouseMapper.dropWideTable(table);
    }

    public void dropBitmapToday(String doDate,String table){

        validArgs(table,doDate);
        clickHouseMapper.dropBitmapToday(doDate,table);

    }

    public void insertBitmapToCk(String table,String doDate,String tagSql,String source){

        validArgs(doDate,table,tagSql,source);

        clickHouseMapper.insertBitmapToCk(table,doDate,tagSql,source);

    }

    public void validArgs(String...args){
        for (String arg : args) {
            //白字符: 参数要么是 空格，要么是回车，要么是\t，\n符号
            if (StringUtils.isBlank(arg)){
                throw new RuntimeException("参数非法!");
            }
        }
    }

}
